package com.woniuxy.order.controller;


import com.woniu.commons.util.JwtUtil;
import com.woniu.zsd.commons.core.model.Result;
import com.woniuxy.order.entity.RecycleReceive;
import com.woniuxy.order.service.IRecycleReceiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.woniu.zsd.commons.core.model.Result;
import com.woniuxy.order.entity.RecycleReceive;
import com.woniuxy.order.service.IRecycleReceiveService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import zsd.waste.dto.OrderWasteDto;
import zsd.waste.form.InsertReForm;

import javax.annotation.Resource;
import java.util.List;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 收货记录表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-13
 */
@RestController
@RequestMapping("/recycle-receive")
@Api(tags = "订单核实操作")
public class RecycleReceiveController {
    @Resource
    private IRecycleReceiveService recycleReceiveService;
    @Resource
    private JwtUtil jwtUtil;

    /**
     * 根据订单Id查询相关废品核实信息操作
     *
     * @return
     */
    @GetMapping("/findOrderIdRr")
    @ApiOperation("根据订单Id查询相关废品核实信息操作")
    public Result<List<RecycleReceive>> findOrderIdRr(Integer orderId, Integer pageNum, Integer pageSize)throws Exception{
        List<RecycleReceive> list = recycleReceiveService.findOrderIdRr(orderId,pageNum,pageSize);
        return Result.getListResult(RecycleReceive.class).setMsg("根据订单Id查询相关废品信息成功").setData(list);
    }


    /**
     * 审核废品核实信息操作
     *
     * @return
     */
    @GetMapping("/ReallyWaste")
    @ApiOperation("审核废品核实信息操作")
    public Result ReallyWaste(Integer id, String verifyRemark,Integer verifyStatus)throws Exception{
         recycleReceiveService.ReallyWaste(id,verifyRemark,verifyStatus);
        return Result.getResult().setMsg("核实成功");
    }


    /**
     * 临时工提交核实订单(支持批量)
     *
     * @return
     */
    @PostMapping("/InsertRr")
    @ApiOperation("临时工提交核实订单(支持批量)")
    public Result InsertRr(@RequestBody List<InsertReForm> forms, @RequestParam Integer orderNum, @RequestHeader String token) throws Exception {
        String id = jwtUtil.parseToken(token).get("id").toString();
        Integer userId = Integer.parseInt(id);
        forms.forEach(form -> form.setReceiverId(userId));
        recycleReceiveService.InsertRr(forms, orderNum, userId);
        return Result.getResult().setMsg("提交成功");
    }



}
